package com.yanqu.road.server.channelserver.cmd.activity.entername;

import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.cross3.activity.EnterNameProto;
import com.yanqu.road.server.channelserver.cmd.ChannelCommand;
import com.yanqu.road.server.channelserver.manager.activity.entername.ChannelEnterNameMgr;
import com.yanqu.road.server.channelserver.manager.activity.entername.EnterNameActivity;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.protocol.ChannelProtocol;

import java.math.BigInteger;

@Cmd(code = ChannelProtocol.N_ENTER_NAME_CHANNEL_USER_VALUE, desc = "玩家数值变更")
public class ChannelEnterNameUserValueCmd extends ChannelCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        EnterNameProto.ChannelEnterNameChannelUserValueReqMsg reqMsg = EnterNameProto.ChannelEnterNameChannelUserValueReqMsg.parseFrom(packet.getBytes());
        int activityId = reqMsg.getActivityId();
        int type = 0;
        if(reqMsg.hasType()){
            type = reqMsg.getType();
        }
        UserBaseInfo userBaseInfo = null;
        if(reqMsg.hasUserBaseInfo()){
            userBaseInfo = PlayerBasePb.parseToUserBaseInfo(reqMsg.getUserBaseInfo());
        }
        EnterNameActivity activity = ChannelEnterNameMgr.getEnterNameActivity(activityId);
        if(activity != null){
            activity.changeUserValue(reqMsg.getUserKey().getUserId(), type, new BigInteger(reqMsg.getValue()), reqMsg.hasParam() ? reqMsg.getParam():"", userBaseInfo);
        }

    }

    @Override
    public void sendData() {

    }
}
